Completed
Push — master ( a87f83...46c1b5 )
by
unknown
01:39
created

es.template.setAbePrecontribDefaultValueIfDoesntExist()ꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
c 1
b 1
f 0
nc 1
dl 0
loc 4
rs 10
nop 0
1
var chai = require('chai');
2
var path = require('path');
3
4
var config = require('../src/cli').config
5
config.set({root: path.join(__dirname,'fixtures')})
6
7
var cmsTemplates = require('../src/cli').cmsTemplates;
8
var Manager = require('../src/cli').Manager;
9
var fse = require('fs-extra');
10
11
describe('Template', function() {
12
  before( function(done) {
13
    Manager.instance.init()
14
      .then(function () {
15
        this.fixture = {
16
          slug: fse.readFileSync(__dirname + '/fixtures/templates/slug.html', 'utf-8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
17
          template: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf-8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
18
          articleEach: fse.readFileSync(__dirname + '/fixtures/templates/article-each-abe.html', 'utf-8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
19
          articlePrecontrib: fse.readFileSync(__dirname + '/fixtures/templates/article-precontribution.html', 'utf-8'),
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
20
          templateKeys: fse.readFileSync(__dirname + '/fixtures/templates/article-keys.html', 'utf-8')
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
21
        }
22
        done()
23
        
24
      }.bind(this))
25
  });
26
27
  /**
28
   * getAbeImport
29
   * 
30
   */
31
  it('cmsTemplates.template.getStructureAndTemplates()', function() {
32
    var res = cmsTemplates.template.getStructureAndTemplates()
33
    chai.expect(res.templates.length).to.be.above(1);
34
  });
35
36
  /**
37
   * getAbeImport
38
   * 
39
   */
40
  it('cmsTemplates.template.getAbeImport()', function() {
41
    var res = cmsTemplates.template.getAbeImport(this.fixture.template)
42
    chai.expect(res).to.have.length(4);
43
  });
44
45
  /**
46
   * includePartials
47
   * 
48
   */
49
  it('cmsTemplates.template.includePartials()', function() {
50
    var template = cmsTemplates.template.includePartials(this.fixture.template)
51
    chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default'}}");
52
  });
53
54
  /**
55
   * cmsTemplates.template.getTemplate
56
   * 
57
   */
58
  it('cmsTemplates.template.getTemplate()', function() {
59
    var template = cmsTemplates.template.getTemplate('article')
60
    chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default' order='1'}}");
61
  });
62
63
  /**
64
   * cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist
65
   * 
66
   */
67
  it('cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist()', function() {
68
    var text = cmsTemplates.template.setAbeSlugDefaultValueIfDoesntExist("")
69
    chai.expect(text).to.be.equal(`{{abe type="slug" source="{{name}}"}}\n`);
70
  });
71
72
  /**
73
   * cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist
74
   * 
75
   */
76
  it('cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist()', function() {
77
    var text = cmsTemplates.template.setAbePrecontribDefaultValueIfDoesntExist("")
78
    chai.expect(text).to.be.equal(`{{abe type='text' key='name' desc='Name' required="true" tab="slug" visible="false"}}\n`);
79
  });
80
81
  /**
82
   * cmsTemplates.template.getAbePrecontribFromTemplates
83
   * 
84
   */
85
  it('cmsTemplates.template.getAbePrecontribFromTemplates()', function() {
86
    var precontrib = cmsTemplates.template.getAbePrecontribFromTemplates([{name: 'slug', template: this.fixture.slug}])
87
    chai.expect(precontrib.fields[0]).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(precontrib.f....0).to.not.be.undefined is not used.
Loading history...
88
  });
89
90
  /**
91
   * cmsTemplates.template.getAbeSlugFromTemplates
92
   * 
93
   */
94
  it('cmsTemplates.template.getAbeSlugFromTemplates()', function() {
95
    var slug = cmsTemplates.template.getAbeSlugFromTemplates([{name: 'slug', template: this.fixture.slug}])
96
    chai.expect(slug.slug).to.not.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to chai.expect(slug.slug).to.not.be.undefined is not used.
Loading history...
97
  });
98
99
  /**
100
   * getTemplate
101
   * 
102
   */
103
  it('cmsTemplates.template.execRequestColumns()', function() { // templateKeys
104
    const pathTemplate = path.join(config.root, config.templates.url)
0 ignored issues
show
Unused Code introduced by
The constant pathTemplate seems to be never used. Consider removing it.
Loading history...
105
    var ar = cmsTemplates.template.execRequestColumns(this.fixture.templateKeys)
106
    chai.expect(ar.indexOf('abe_meta.date')).to.be.above(-1);
107
  });
108
109
  /**
110
   * cmsTemplates.insertDebugtoolUtilities
111
   * 
112
   */
113
  it('cmsTemplates.insertDebugtoolUtilities()', function() {
114
    var txt = cmsTemplates.insertDebugtoolUtilities('</body>');
115
    chai.expect(txt.length).to.above(10);
116
  });
117
118
  /**
119
   * cmsTemplates.encodeAbeTagAsComment
120
   * 
121
   */
122
  it('cmsTemplates.encodeAbeTagAsComment()', function() {
123
    var txt = cmsTemplates.encodeAbeTagAsComment(this.fixture.articleEach);
124
    chai.expect(txt.indexOf('{')).to.equal(-1);
125
  });
126
});
127